//
//  AboutFLZViewController.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/11.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "AboutFLZViewController.h"
#import "SettingContentTableViewCell.h"
#import "SettingArrowTableViewCell.h"
#import "PrivacyViewController.h"
@interface AboutFLZViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)NSMutableArray * contentCellArr;
@property (nonatomic, strong)NSMutableArray * arrowCellArr;
@property (nonatomic, strong)UILabel * visionLab;
@end

@implementation AboutFLZViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"关于福乐猪";
    //返回按钮
    UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, 14/WIDTH_6_SCALE + 24 + 20, 24/WIDTH_6_SCALE, 30/WIDTH_6_SCALE)];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"out"] forState:UIControlStateNormal];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
}
#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVI_HEIGHT - BOTTOM_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[SettingArrowTableViewCell class] forCellReuseIdentifier:NSStringFromClass([SettingArrowTableViewCell class])];
        [_tableView registerClass:[SettingContentTableViewCell class] forCellReuseIdentifier:NSStringFromClass([SettingContentTableViewCell class])];
        _tableView.tableFooterView = [UIView new];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 184/WIDTH_6_SCALE)];
        _headerView.backgroundColor = [UIColor whiteColor];
        UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, _headerView.bottom - 1/WIDTH_6_SCALE, SCREEN_WIDTH - 36/WIDTH_6_SCALE, 1/WIDTH_6_SCALE)];
        lineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:lineView];
        //标识
        UIImageView * iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 26/WIDTH_6_SCALE, 96/WIDTH_6_SCALE, 43/WIDTH_6_SCALE)];
        iconImgView.centerX = self.view.centerX;
        iconImgView.backgroundColor = [UIColor orangeColor];
        [_headerView addSubview:iconImgView];
        //版本号
        self.visionLab = [[UILabel alloc] initWithFrame:CGRectMake(0, iconImgView.bottom + 8/WIDTH_6_SCALE, SCREEN_WIDTH, 10/WIDTH_6_SCALE)];
        self.visionLab.centerX = iconImgView.centerX;
        [self label:self.visionLab withFont:DEF_FontSize_10 withText:@"版本号1.0.0" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:_headerView];
    }return _headerView;
}
- (NSMutableArray *)contentCellArr{
    if (!_contentCellArr) {
        _contentCellArr = @[@{@"title":@"官方微信号", @"content":@"中裕福乐猪"},
                            @{@"title":@"官方网站", @"content":@"www.zyzbol.com"},
                            @{@"title":@"客服电话", @"content":@"4006-228-086"},].mutableCopy;
    }return _contentCellArr;
}
- (NSMutableArray *)arrowCellArr{
    if (!_arrowCellArr) {
        _arrowCellArr = @[@{@"title":@"隐私规则"}].mutableCopy;
    }return _arrowCellArr;
}
#pragma mark - tableViewDelegate和tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = nil;
    if (indexPath.row != self.contentCellArr.count) {
        SettingContentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SettingContentTableViewCell class]) forIndexPath:indexPath];
        if (indexPath.row != 2) {
            cell.blackModel = self.contentCellArr[indexPath.row];
        }else{
            cell.blueModel = self.contentCellArr[indexPath.row];
        }
        return cell;
    }else{
        SettingArrowTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SettingArrowTableViewCell class]) forIndexPath:indexPath];
        cell.model = self.arrowCellArr[indexPath.row - self.contentCellArr.count];
        return cell;
    }return cell;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 56/WIDTH_6_SCALE;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        PrivacyViewController * privacyVC = [[PrivacyViewController alloc] init];
        [self.navigationController pushViewController:privacyVC animated:YES];
    }
}
#pragma mark - action
- (void)backBtnClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
